<template>
    <el-button class="mb5" style="float: right" type="primary" @click="getList">
        <template #icon>
            <i-ep-search/>
        </template>
        刷新
    </el-button>
    <el-table v-adaptive="280" :border="true" :data="prescriptionApplyList"
              :header-cell-style="$headerCellStyle" :stripe="true"
              highlight-current-row>
        <el-table-column fixed="left" label="明细" type="expand">
            <template #default="props">
                <div m="4">
                    <el-table :data="props.row.prescriptionItemVos" :row-class-name="tableRowClassName"
                              :stripe="true" highlight-current-row>
                        <el-table-column fixed="left" width="100px"/>
                        <el-table-column :align="'center'" label="药品" prop="drugName" width="160"/>
                        <el-table-column :align="'center'" label="单次用量" prop="singleDosage" width="170">
                            <template #default="scope">
                                            <span> {{ scope.row.singleDosage }}<dict-data-tag
                                                :options="dictDataMap['dose_unit']" :value="scope.row.singleUnit"
                                                style="margin: -23px -20px 0px 50px"/></span>
                            </template>
                        </el-table-column>
                        <el-table-column :align="'center'" label="数量" prop="num" width="120">
                            <template #default="scope">
                                            <span>{{ scope.row.num }} <dict-data-tag
                                                :options="dictDataMap['spec_unit']" :value="scope.row.packSize === '1' ?
                                                    scope.row.minUnits : scope.row.packageUnits"
                                                style="margin: -23px -20px 0px 27px"/></span>
                            </template>
                        </el-table-column>
                        <el-table-column :align="'center'" label="单价" prop="price" width="120">
                            <template #default="scope">
                                {{ parseFloat(scope.row.price).toFixed(2) }}元
                            </template>
                        </el-table-column>
                        <el-table-column :align="'center'" label="总价" prop="sumPrice" width="120">
                            <template #default="scope">
                                {{ parseFloat(scope.row.sumPrice).toFixed(2) }}元
                            </template>
                        </el-table-column>
                        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="规格"
                                         prop="packageSpec"
                                         width="130"/>
                        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="医生说明"
                                         prop="remarks"
                                         width="220px"/>
                    </el-table>
                </div>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="申请序号" prop="applyNo"
                         width="100"/>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="处方属性" prop="prescAttr"
                         width="80">
            <template #default="scope">
                <dict-data-tag :options="dictDataMap['prescription_type']"
                               :value="scope.row.prescAttr"/>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="处方分类" prop="itemClass"
                         width="70">
            <template #default="scope">
                <dict-data-tag :options="dictDataMap['bill_item_class_dict']"
                               :value="scope.row.itemClass"/>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="收费标志" prop="chargeFlag"
                         width="135">
            <template #default="scope">
                <dict-data-tag :options="dictDataMap['charge_flag_dict']"
                               :value="scope.row.chargeFlag"/>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" label="开单科室" prop="applyDeptName"/>
        <el-table-column :align="'center'" label="开单时间" prop="createTime" width="130"/>
        <el-table-column :align="'center'" label="发药药房" prop="implementDeptName"/>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="发药标志" prop="confirmFlag"
                         width="90">
            <template #default="scope">
                <dict-data-tag :options="dictDataMap['grant_flag']" :value="scope.row.confirmFlag"/>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" label="发药执行人" prop="implementUserName"/>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="发药时间" prop="grantTime"
                         width="130">
            <template #default="scope">
                <span>{{ $parseTime(scope.row.grantTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="备注信息"
                         prop="remarks"/>
        <el-table-column :align="'center'" label="确认退药人" prop="returnDrugUser"/>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="确认退药时间"
                         prop="returnDrugTime"
                         width="130">
            <template #default="scope">
                <span>{{ $parseTime(scope.row.returnDrugTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="诊断名称" prop="icdName"
                         width="90"/>
    </el-table>
</template>

<script lang="ts" setup>
import {useUserStoreHook} from "@/store/modules/user.ts";
import {useDictStoreHook} from "@/store/modules/dict.ts";
import {listPrescriptionApply} from "@/api/patient/prescriptionApply.ts";

const {proxy} = getCurrentInstance() as any;
const currentSelectDept = proxy.$currentSelectDept

const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo;
const dictStore = useDictStoreHook();
let dictDataMap = ref(
    dictStore.isTypeGetData(
        'prescription_type', 'bill_item_class_dict', 'dose_unit', 'spec_unit',
        'charge_flag_dict', 'grant_flag'
    )
);

const props = defineProps({
    inoroutFlag: {
        type: String,
        default: "4"
    },
    confirmFlag: {
        type: String,
        default: ""
    },
    isShowQuery: {
        type: Boolean,
        default: true
    }
})
const queryParams = ref<any>({
    patientId: "",
    clinicId: "",
    orgId: userInfo.orgId,
    name: "",
    itemName: '',
    inoroutFlag: props.inoroutFlag,
    confirmFlag: props.confirmFlag
})

const prescriptionApplyList = ref([]);


// 检查
function getPrescriptionApplyList(clinicId: string) {
    queryParams.value.clinicId = clinicId
    getList()
}

function getList() {
    listPrescriptionApply(queryParams.value).then((response: any) => {
        prescriptionApplyList.value = response.data.prescriptionApplyVos;
    });
}

const tableRowClassName = () => {
    return 'success-row'
}

defineExpose({
    getPrescriptionApplyList,
    getList
})

</script>

<style scoped>

</style>
